[Rails] Calling a method from a view using link_to_function

Posted by Jeff on Stack Overflow See other posts from Stack Overflow or by Jeff
Published on 2010-04-22T14:27:52Z Indexed on 2010/04/22 14:53 UTC
Read the original article Hit count: 390

Filed under:
|
|

Hello! I'm trying to have an image that when clicked associates the selected guideline to a project. I'm using link_to_function which somewhat behaves but I can not get the method I am calling in the link_to_function to redirect to another page. Is there a better way to do this? Below is a bit of my code. I can paste in additional parts if necessary:

<% @guidelines.each do |guideline| %>
 <tr>
    <td align='center'><%= link_to_function image_tag("../../../images/icons/action_add.png"), add_guideline(guideline)  %></td>
          <td><%=h guideline.title %></td>

My GuidelinesController.helper method looks like this:

  def add_guideline(guideline)
           @project = Project.find(params[:project_id])
           @project.guidelines << guideline
           @project.save   

           redirect_to dashboard_path #doesn't work :(
    end

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about rails